package com.crm.system.jobhandle;

import com.crm.system.service.customerManager.CustomerService;
import com.crm.system.service.index.FirstPageService;
import com.crm.system.service.returnMoney.ReturnMoneyService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ReturnMoneyJob {

    private static Logger logger = LoggerFactory.getLogger(ReturnMoneyJob.class);

    @Autowired
    private ReturnMoneyService returnMoneyService;

    @Autowired
    private CustomerService customerService;

    @Autowired
    private FirstPageService firstPageService;

    /**
     * 每月一号执行(统计业务员每月业绩)
     */
    @XxlJob("getSalesmanResultsByMonth")
    public void getSalesmanResultsByMonth() throws Exception {
        XxlJobHelper.log("CRM-JOB-getSalesmanResultsByMonth");
        returnMoneyService.getSalesmanResultsByMonth();
    }

    /**
     * 每月一号执行(统计业务员每月业绩)
     */
    @XxlJob("getSalesmanResultsByYear")
    public void getSalesmanResultsByYear() throws Exception {
        XxlJobHelper.log("CRM-JOB-getSalesmanResultsByYear");
        returnMoneyService.getSalesmanResultsByYear();
    }

    /**
     * 每周执行一次(客户会员到期时间设置为流失客户)
     */
    @XxlJob("updateLoseCustomer")
    public void updateLoseCustomer() throws Exception {
        XxlJobHelper.log("CRM-JOB-updateLoseCustomer");
        customerService.updateLoseCustomer();
    }

    /**
     * 每周执行一次(会员最大合同到期时间设置为客户会员到期时间)
     */
    @XxlJob("updateCustomerMembershipExpirationTm")
    public void updateCustomerEndDate() throws Exception {
        XxlJobHelper.log("CRM-JOB-updateCustomerMembershipExpirationTm");
        customerService.updateCustomerMembershipExpirationTm();
    }

    /**
     * 首页统计全部个人业绩
     */
    @XxlJob("firstPageSalesman")
    public String firstPageSalesman() {
        XxlJobHelper.log("CRM-JOB-firstPageSalesman");
        firstPageService.firstPageSalesman();
        return "操作成功";
    }

    /**
     * 首页统计按年个人业绩
     */
    @XxlJob("firstPageSalesmanYear")
    public String firstPageSalesmanYear() {
        XxlJobHelper.log("CRM-JOB-firstPageSalesmanYear");
        firstPageService.firstPageSalesmanByYear();
        return "操作成功";
    }

    /**
     * 首页统计按年月个人业绩
     */
    @XxlJob("firstPageSalesmanByMonth")
    public String firstPageSalesmanByMonth() {
        XxlJobHelper.log("CRM-JOB-firstPageSalesmanByMonth");
        firstPageService.firstPageSalesmanByMonth();
        return "操作成功";
    }


}
